<template>
  <div style="margin:0 auto; width: 80%">
    <el-table
      :data="data.slice((pagination.currentPage-1) * pagination.pagesize, pagination.currentPage
    * pagination.pagesize)" style="width: 96%; margin: 0 auto; border-radius: 10px"
      height="500px"
    >
      <el-table-column
        prop="media[0].mediaPath"
        label="商品图"
        width="200"
      >
        <template slot-scope="scope">
          <el-image
            :src="scope.row.media[0].mediaPath"
            style="width: 80px; height: 80px"
          ></el-image>
        </template>
      </el-table-column>
      <el-table-column
        prop="goodName"
        label="商品名"
        width="300"
      ></el-table-column>
      <el-table-column
        prop="stock"
        label="库存"
        width="150"
      ></el-table-column>
      <el-table-column
        label="状态"
        width="150"
      >
        <template slot-scope="scope">
          <el-button v-on:click="dialogFormVisible = true"
          >
            下架
          </el-button>
          <el-dialog
            title="发布商品"
            :visible.sync="dialogFormVisible"
            :destroy-on-close="true"
            append-to-body
          >
            <el-form :model="form">
              <el-form-item label="下架原因" :label-width="formLabelWidth">
                <el-input v-model="offShelfReason" autocomplete="off"></el-input>
              </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
              <el-button @click="dialogFormVisible = false">取 消</el-button>
              <el-button type="primary" @click="change(pagination.pagesize * (pagination.currentPage - 1) + scope.$index)">确 定</el-button>
            </div>
          </el-dialog>
        </template>
      </el-table-column>
    </el-table>
    <div style="float: right; position: relative; right: 5%">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        layout="prev, pager, next, jumper"
        :current-page="pagination.currentPage"
        :page-size="pagination.pagesize"
        :total="data.length">
      </el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  dialogFormVisible:false,
  name: "offShelf",
  model:{
    prop: ['data']
  },
  props: ['data'],
  data() {
    return {
      offShelfReason: "",
      pagination : {
        currentPage: 1,
        pagesize: 4,
        list: []
      },
    }
  },
  methods:{
    offShelf: function (){
      this.dialogFormVisible = true;
    },
    change: function (index) {
      this.$api.seller.goodsOffShelf({
        goodId:this.data[index].goodId,
        offShelfReason:this.offShelfReason
      }).then(res=>{
        console.log(res.data.code)
      })
      this.dialogFormVisible = false;
    },
    handleSizeChange(val) {
      this.pagination.pagesize = val;
    },
    handleCurrentChange(val) {
      this.pagination.currentPage = val;
    },
    handList: function () {
      this.pagination.list = this.data;
    },
    setType: function () {
      // if (this.data[pagination.pagesize * (pagination.currentPage - 1) + scope.$index].freeze) {
      //   return "danger"
      // } else {
      //   return "success"
      // }
      return "success"
    }
  },
  created() {
    // alert(this.data.slice((this.pagination.currentPage-1)*this.pagination.pagesize,this.pagination.currentPage*this.pagination.pagesize))
    // this.handList()

  }
}
</script>

<style scoped>
table.title{
  position: fixed;
  width: 98%;
  height: 10%;
  margin: 0 auto;
  top: 0;
  background-color: #037bd2;
}
button.title_button{
  background-color: #037bd2;
  font-size: xx-large;
  color: whitesmoke;
  transition-duration: 0.4s;
  border: none;
  width: 100%;
}
td{
  border-style: none;
  font-family: "Microsoft YaHei",serif;
}
span{
  text-align: center;
}
img {
  border-radius: 20px;
  width: 100px;
  height: 100px;
}
#imglist img{
  float: left;
}
.left:hover{
  background-color: slategrey;
}
a.astyle{
  background-color: #037bd2;
  font-size: xx-large;
  color: whitesmoke;
  transition-duration: 0.4s;
  border: none;
  width: 100%;
  text-decoration: none;
  cursor:pointer
}
.astyle:hover{
  color: lightgray;
}
input.dj{
  width: 40%;
  margin: 0 auto;
  background-color: #4CAF50; /* Green */
  border: none;
  color: white;
  margin-top: 5%;
  padding: 5px 10px;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  border-radius: 5px;
}
.dj:active {
  background-color: #3e8e41;
  box-shadow: 0 5px #99eab7;
  transform: translateY(4px);
  border: none;
}
.but1 {
  margin: 0 auto;
  background-color: #4CAF50; /* Green */
  border: none;
  color: white;
  margin-top: 5%;
  padding: 5px 10px;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  border-radius: 5px;
}
.but1:active {
  background-color: #3e8e41;
  box-shadow: 0 5px #99eab7;
  transform: translateY(4px);
}
td{
  margin: 0 auto;
  margin-top: 5%;
}

.table {
  margin: 0 auto;
  border: 2px solid steelblue;
  text-align: center;
  width: 1000px;
  /*height: 600px;*/
  border-collapse: separate;
  border-spacing: 0;
  border-radius: 10px 10px 0 0;
  line-height: 50px;
}
.tr1 {
  background: steelblue;
  border-radius: 10px;
  border: 2px solid steelblue;
  color: white;
  font-family: "Microsoft Himalaya", sans-serif;
  text-align: center;
}
.tr2 {
  background: white;
  font-family: "Microsoft Himalaya", sans-serif;
  color: #4F4F4F;
  border-radius: 10px;
  border: 2px solid rgba(0, 0, 0, 0);
}
.tr2:hover {
  background: rgba(220, 220, 220, 1);
}
</style>
